define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sta/bios/index' + location.search,
                    summonth_url: 'sta/bios/summonth',
                    add_url: 'sta/bios/add',
                    edit_url: 'sta/bios/edit',
                    del_url: 'sta/bios/del',
                    multi_url: 'sta/bios/multi',
                    import_url: 'sta/bios/import',
                    dragsort_url: '',
                    table: 'sta_bios',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id ASC, createtime ASC',
                pageSize: 500,                  // @DEMO
                pageList: [500],

                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'factory_id',  title: __('Factory_id'),  operate: '=', searchList: Config.factoryList },
                        {field: 'storesub_id', title: __('Storesub_id'), operate: '=', searchList: Config.storesubList },
                        {field: 'storea_id',   title: __('Storea_id'),   operate: '=', searchList: Config.storeaList },
                        // {field: 'gene_id', title: __('Gene_id'), operate: '='},
                        {field: 'pinxi_id', title: __('Pinxi_id'), operate: '=', searchList: Config.pinxiList },
                        {field: 'a1', title: __('A1'), operate: false},
                        {field: 'a2', title: __('A2'), operate: false},
                        {field: 'a3', title: __('A3'), operate: false},
                        {field: 'b1', title: __('B1'), operate: false},
                        {field: 'b2', title: __('B2'), operate: false},
                        {field: 'b3', title: __('B3'), operate: false},
                        // {field: 'b4', title: __('B4'), operate: false},
                        // {field: 'b5', title: __('B5'), operate: false},
                        {field: 'c1', title: __('C1'), operate: false},
                        {field: 'c2', title: __('C2'), operate: false},
                        {field: 'c3', title: __('C3'), operate: false},
                        {field: 'd1', title: __('D1'), operate: false},
                        {field: 'd2', title: __('D2'), operate: false},
                        {field: 'd3', title: __('D3'), operate: false},
                        {field: 'e1', title: __('E1'), operate: false},
                        {field: 'e2', title: __('E2'), operate: false},
                        {field: 'e3', title: __('E3'), operate: false},
                        {field: 'f1', title: __('F1'), operate: false},
                        {field: 'f2', title: __('F2'), operate: false},
                        {field: 'f3', title: __('F3'), operate: false},
                        {field: 'g1', title: __('G1'), operate: false},
                        {field: 'g2', title: __('G2'), operate: false},
                        {field: 'g3', title: __('G3'), operate: false},
                        {field: 'h1', title: __('H1'), operate: false},
                        {field: 'h2', title: __('H2'), operate: false},
                        {field: 'h3', title: __('H3'), operate: false},
                        {field: 'i1', title: __('I1'), operate: false},
                        {field: 'i2', title: __('I2'), operate: false},
                        {field: 'i3', title: __('I3'), operate: false},
                        // {field: 'j1', title: __('J1'), operate: false},
                        // {field: 'j2', title: __('J2'), operate: false},
                        // {field: 'j3', title: __('J3'), operate: false},
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden'),"deleted":__('Deleted'),"locked":__('Locked')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate: '=', searchList: Config.monthList , formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM" },
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'sta/bios/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'sta/bios/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'sta/bios/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        summonth: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
